package com.ermace.robo.jumper.game.Player;

import java.util.List;
import java.util.Random;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;

import com.ermace.robo.jumper.R;
import com.ermace.robo.jumper.game.GameView;
import com.ermace.robo.jumper.game.Line;
import com.ermace.robo.jumper.game.Map;
import com.ermace.robo.jumper.game.Sound;
import com.ermace.robo.jumper.game.GameObjects.Bitmaps;
import com.ermace.robo.jumper.game.GameObjects.Drawable;
import com.ermace.robo.jumper.game.GameObjects.GameObject;

public abstract class Robot implements Drawable {

	public enum HorizontalOrientation {
		RIGHT, LEFT, NONE;
	}

	public enum VerticalOrientation {
		DOWN, UP, NONE;
	}

	public enum State {
		ALIVE, DEATH, RESPAWNED;
	}


	protected static final double RESPAWN_TIME = 4.0;
	private static final double	RESPAWNED_TIME = 2.0;
	
	public static final double RADIUS_HORIZONTAL = GameView.SCREEN_WIDTH / 30; //TODO
	public static final double RADIUS_VERTICAL = GameView.SCREEN_WIDTH / 25;
	private static final double RADIUS_FEET = RADIUS_HORIZONTAL/2.05;
	private static final double RADIUS_HIP = RADIUS_HORIZONTAL / 2.05;
	private static final double HEIGHT_HIP = RADIUS_VERTICAL / 4;
	private static final double RADIUS_SHOULDERS = 9 * RADIUS_HORIZONTAL / 10;
	private static final double HEIGHT_SHOULDERS = 2 * RADIUS_VERTICAL / 3;
	private static final double RADIUS_HEAD = RADIUS_HORIZONTAL / 5;
	private static final double HEIGHT_HEAD = 9 * RADIUS_VERTICAL / 10;

	private static final double MAX_X = GameView.SCREEN_WIDTH - RADIUS_VERTICAL - 1;
	private static final double MIN_X = 1 + RADIUS_VERTICAL;
	public static final double MAX_Y = GameView.SCREEN_HEIGHT - RADIUS_HORIZONTAL - 2;
	private static final double MIN_Y = GameView.TOP_HEADER_HEIGHT;

	private final double JUMP_SPEED;
	private final double MOVE_SPEED;
	private final double GRAVITY;
	private final double MAX_JUMP_HEIGHT;
	private static final Bitmap Spritesheet = Bitmaps.getInstance().getBitmap(R.drawable.spritesheet);
	private static final Bitmap ARROW = Bitmaps.getInstance().getBitmap(R.drawable.arrow_up_icon);
	private final List<Robot> robots;
	private final RobotColour Spritesheet_color;
	
	private Rect src1 = new Rect(0,0,Spritesheet.getWidth() /9 , Spritesheet.getHeight() /10);

	private Position position;
	protected State state = State.RESPAWNED;
	private HorizontalOrientation horizontalOrientation = HorizontalOrientation.NONE;
	private VerticalOrientation verticalOrientation = VerticalOrientation.NONE;
	private double verticalSpeed = 0;
	private double horizontalAcceleration = 0;
	private double horizontalSpeed = 0;
	private Map map;
	private GameObject standingOn = null;
	protected double timeDeath;
	protected double timeRespawned;

	protected int lives = 3;
	
	private Line[] feetLines = new Line[3];
	private Line[] headShoulderLines = new Line[4];
	private Line[] borderLines = new Line[2];
	private Line[] horizontalLines = new Line[2];
	
	private Rect dst;
	private Rect src;
	private int toDraw = 0;
	private int currentFrame = 0;
	private int framesPast = 0;

	private Position newPos;

	protected Context context;
	
	private boolean exploding = false;

	public Robot(double gravity, double moveSpeed, Position position, double jumpSpeed, Map map, List<Robot> robots, RobotColour colour, Context context) {
		MOVE_SPEED = moveSpeed;
		JUMP_SPEED = jumpSpeed;
		GRAVITY = gravity;
		MAX_JUMP_HEIGHT = JUMP_SPEED * JUMP_SPEED/(2 * GRAVITY);
		
		Spritesheet_color = colour;
		this.map = map;
		this.robots = robots;
		this.context = context;
		this.setPosition(position);
	}

	public Robot(double gravity, double moveSpeed, double jumpSpeed, Map map, List<Robot> robots, RobotColour colour, Context context) {
		MOVE_SPEED = moveSpeed;
		JUMP_SPEED = jumpSpeed;
		GRAVITY = gravity;
		MAX_JUMP_HEIGHT = JUMP_SPEED * JUMP_SPEED/(2 * GRAVITY);

		Spritesheet_color = colour;
		this.map = map;
		this.robots = robots;
		this.context = context;
		respawn();
	}

	//	Getters, setters en checkers		//
	/**
	 * @return the position
	 */
	public Position getPosition() {
		return position;
	}

	/**
	 * @param position the position to set
	 */
	private void setPosition(Position position) {
		this.position = position;
		if (newPos == null)
			newPos = position;
		
		updateLines();
	}


	/**
	 * @param horizontalAcceleration the horizontalAcceleration to set
	 */
	public void setHorizontalAcceleration(double horizontalAcceleration) {
		this.horizontalAcceleration = horizontalAcceleration;
	}
	
	public double getMaxJumpHeight() {
		return MAX_JUMP_HEIGHT;
	}
	
	public boolean canJumpOn(GameObject obj) { //TODO
		double distX = Math.abs(obj.getRect().left - getPosition().getX());
		double other = Math.abs(obj.getRect().right - getPosition().getX());
		
		if (other < distX) {
			distX = other;
		}
		
		double distY = Math.abs(obj.getRect().top - (getPosition().getY() + RADIUS_HORIZONTAL / 2));
		
		double time = distX / MOVE_SPEED;
		double height = GRAVITY / 2 * time * time + JUMP_SPEED * time;
		
		if (height > distY)
			return true;
		
		return false;
	}
	
	/**
	 * @return the horizontalOrientation
	 */
	public HorizontalOrientation getHorizontalOrientation() {
		return horizontalOrientation;
	}

	/**
	 * @return the verticalOrientation
	 */
	public VerticalOrientation getVerticalOrientation() {
		return verticalOrientation;
	}
	

	
	public Line[] getHorizontalLines()
	{
		return horizontalLines;
	}
	
	public Line[] getBorderLines()
	{
		return borderLines;
	}

	public boolean isAlive() {
		return state != State.DEATH;
	}

	public boolean isExploding()
	{
		return exploding;
	}

	protected abstract double getKillScore();
	
	public GameObject getObjectStandingOn() {
		return standingOn;
	}
	
	public boolean isStandingOn(GameObject obj) {
		if (standingOn == null)
			return false;
		
		return standingOn.equals(obj);
	}
		
	//	Deel bewegingen		//
	
//	public void move(MotionEvent event) {	//TODO remove
//		if (event == null)
//			horizontalOrientation = HorizontalOrientation.NONE;
//		else if (event.getX() < getPosition().getX())
//			horizontalOrientation = HorizontalOrientation.LEFT;
//		else if (event.getX() > getPosition().getX())
//			horizontalOrientation = HorizontalOrientation.RIGHT;
//	}

	public void move(Position pos) {
		horizontalOrientation = HorizontalOrientation.NONE;
		if (pos != null) {
			if (pos.getX() < getPosition().getX() - 2 * RADIUS_HORIZONTAL / 3)
				horizontalOrientation = HorizontalOrientation.LEFT;
			else if (pos.getX() > getPosition().getX() + 2 * RADIUS_HORIZONTAL / 3)
				horizontalOrientation = HorizontalOrientation.RIGHT;
		}
	}

	public boolean jump() {
		if (verticalOrientation == VerticalOrientation.NONE) {
			verticalSpeed = JUMP_SPEED;
			verticalOrientation = VerticalOrientation.UP;
			standingOn = null;
			horizontalAcceleration = 0;
			Sound.getInstance(context).jumpSound();
			return true;
		}		
		return false;
	}
	
	/**
	 * 
	 */
	private void jumpWhenKill() {
		verticalOrientation = VerticalOrientation.UP;
		verticalSpeed = JUMP_SPEED/3;
	}

	public void stop() {
		horizontalOrientation = HorizontalOrientation.NONE;
		updateHorizontalSpeed(0.01);
	}
	
	//	Deel update		//
	
	public void updatePosition(double elapsedTimeMS) {
		double toAddHorizontal = 0;
		double toAddVertical = 0;
		double interval = elapsedTimeMS / 1000.0;

		if (state != State.DEATH) {
			if (horizontalAcceleration == 0) {	// Geen horizontale versnelling
				if (horizontalOrientation == HorizontalOrientation.LEFT)
					horizontalSpeed = -MOVE_SPEED;
				else if (horizontalOrientation == HorizontalOrientation.RIGHT)
					horizontalSpeed = MOVE_SPEED;
			}
			
//			if (Math.abs(horizontalSpeed) == MOVE_SPEED) {
//				if (horizontalOrientation == HorizontalOrientation.LEFT)
//					toAddHorizontal -= MOVE_SPEED * interval;
//				else if (horizontalOrientation == HorizontalOrientation.RIGHT)
//					toAddHorizontal += MOVE_SPEED * interval;
//			} else {
			double positionAcc = 0;
			if (Math.abs(horizontalSpeed) == MOVE_SPEED)
				positionAcc = horizontalAcceleration / 2 * interval * interval;
			
			if (horizontalOrientation == HorizontalOrientation.LEFT) {
				toAddHorizontal += -positionAcc + horizontalSpeed * interval;
			} else if (horizontalOrientation == HorizontalOrientation.RIGHT) {
				toAddHorizontal += positionAcc + horizontalSpeed * interval;
			} else {
				if (horizontalAcceleration != 0) { // momentum is a bitch still going left or right
					if (horizontalSpeed < 0) {	// going left
						toAddHorizontal += -positionAcc + horizontalSpeed * interval;
					} else if (horizontalSpeed > 0) { // going right
						toAddHorizontal += positionAcc + horizontalSpeed * interval;
					}
				}
			}
			updateHorizontalSpeed(interval);
//			}
			
			if (verticalOrientation != VerticalOrientation.NONE) {
				toAddVertical += GRAVITY * interval * interval / 2 + verticalSpeed * interval;
				verticalSpeed += GRAVITY * interval;
				if (verticalSpeed > 0 && verticalOrientation != VerticalOrientation.DOWN)
					verticalOrientation = VerticalOrientation.DOWN;
				
				if (horizontalOrientation == HorizontalOrientation.NONE)
					horizontalSpeed = 0;
				else if (horizontalOrientation == HorizontalOrientation.LEFT)
					horizontalSpeed = -MOVE_SPEED;
				else
					horizontalSpeed = MOVE_SPEED;
			}

			newPos = getPosition().add(new Position(toAddHorizontal, toAddVertical));
			//setPosition(getPosition().add(toAdd));
//			newX = newPos.getX();
//			newY = newPos.getY();
//			setPosition(new Position(newX, newY));	//	TODO
			updateLines();
		} else {
			timeDeath -= elapsedTimeMS / 1000;
			if (timeDeath <= 0)
				respawn();
		}
		
		if (state == State.RESPAWNED) {
			timeRespawned -= elapsedTimeMS / 1000;
			if (timeRespawned <= 0)
				state = State.ALIVE;
		}
	}

	/**
	 * @param interval
	 */
	private void updateHorizontalSpeed(double interval) {
		int add = 1;
		if (horizontalOrientation == HorizontalOrientation.LEFT
				|| (horizontalOrientation == HorizontalOrientation.NONE && horizontalSpeed > 0) )
			add = -1;
		
		double newSpeed = horizontalSpeed + add * horizontalAcceleration * interval;
		horizontalSpeed = Math.max(-MOVE_SPEED, newSpeed);
		horizontalSpeed = Math.min(MOVE_SPEED, horizontalSpeed);
	}
	


	private void updateLines() {
		double x = getPosition().getX();
		double y = getPosition().getY();

		double newX = newPos.getX();
		double bottom = getPosition().getY() + RADIUS_VERTICAL;
		double newBottom = newPos.getY() + RADIUS_VERTICAL;

		feetLines[0] = new Line(x - RADIUS_FEET, y + RADIUS_VERTICAL, x + RADIUS_FEET, y + RADIUS_VERTICAL);
		feetLines[1] = new Line(getPosition().getX() - RADIUS_FEET, bottom, 
				newX - RADIUS_FEET, newBottom);
		feetLines[2] = new Line(getPosition().getX() + RADIUS_FEET, bottom, 
				newX + RADIUS_FEET, newBottom);
		
		//Left
		borderLines[0] = new Line(x - RADIUS_HORIZONTAL, y - RADIUS_VERTICAL, x - RADIUS_HORIZONTAL, y + RADIUS_VERTICAL );
		//Right
		borderLines[1] = new Line(x + RADIUS_HORIZONTAL, y - RADIUS_VERTICAL, x + RADIUS_HORIZONTAL, y + RADIUS_VERTICAL );
		
		//Bottom
		horizontalLines[0] = new Line(x - RADIUS_HORIZONTAL, y - RADIUS_VERTICAL, x + RADIUS_HORIZONTAL, y - RADIUS_VERTICAL);
		//Top
		horizontalLines[1] = new Line(x - RADIUS_HORIZONTAL, y + RADIUS_VERTICAL, x + RADIUS_HORIZONTAL, y + RADIUS_VERTICAL);
		
		// shoulderHeadLeft 
		headShoulderLines[0] = new Line(x - RADIUS_SHOULDERS, y - HEIGHT_SHOULDERS,
				x - RADIUS_HEAD, y - HEIGHT_HEAD);
		
		// shoulderHeadRight
		headShoulderLines[1]= new Line(x + RADIUS_SHOULDERS, y - HEIGHT_SHOULDERS,
				x + RADIUS_HEAD, y - HEIGHT_HEAD);
		
		// HeadTopLeft
		headShoulderLines[2]= new Line(x + RADIUS_HEAD, y - HEIGHT_HEAD,
				x, y - RADIUS_VERTICAL);
		
		// HeadTopRight
		headShoulderLines[3]= new Line(x - RADIUS_HEAD, y - HEIGHT_HEAD,
				x, y - RADIUS_VERTICAL);
	}
	
	public void kill()
	{
		if(state == State.ALIVE)
			killed();
	}
	
	private void killed() {
		state = State.DEATH;
		timeDeath = RESPAWN_TIME;
		exploding = true;
		currentFrame = 0;
		resetState();
	}

	/**
	 * 
	 */
	protected void resetState() {
		horizontalOrientation = HorizontalOrientation.NONE;
		verticalOrientation = VerticalOrientation.NONE;
		horizontalAcceleration = 0;
		verticalSpeed = 0;
		standingOn = null;
	}


	
	//	Deel collision		//
	
	/**
	 * 
	 */
	public void checkCollision(List<GameObject> list) {
		
		if (! checkCollisionRobot())
			checkCollisionMap(list);

		setPosition(newPos);
	}

	private boolean checkCollisionMap(List<GameObject> list) {
		double newX = Math.max(newPos.getX(), MIN_X);
		newX = Math.min(newX, MAX_X);
		if (newX == MAX_X || newX == MIN_X)
			horizontalSpeed = 0;
		if (newX == MAX_X && horizontalOrientation == HorizontalOrientation.LEFT)
			updateHorizontalSpeed(0.01);
		if (newX == MIN_X && horizontalOrientation == HorizontalOrientation.RIGHT)
			updateHorizontalSpeed(0.01);

		double newY = Math.min(newPos.getY(), MAX_Y);
		if (newY == MAX_Y) {
			verticalOrientation = VerticalOrientation.NONE;
			verticalSpeed = 0;
		}

		Position collision = null;
		double bottom = getPosition().getY() + RADIUS_VERTICAL;

		if (verticalOrientation == VerticalOrientation.DOWN) {
			for(GameObject obj: list) {
				collision = obj.collide(feetLines[1]);
				if (collision != null) { // left foot collided with an object
					collision = collision.add(new Position(RADIUS_FEET, 0));
					standingOn = obj;
					break;
				}

				collision = obj.collide(feetLines[2]);
				if (collision != null) { // right foot collided with an object
					collision = collision.subtract(new Position(RADIUS_FEET, 0));
					standingOn = obj;
					break;
				}
			}
		}

		if (standingOn != null && collision == null) {
			if (!( standingOn.contains(new Position(getPosition().getX() - RADIUS_FEET, bottom + 1)) 
					|| standingOn.contains(new Position(getPosition().getX() + RADIUS_FEET, bottom + 1)) ) ) {
				verticalOrientation = VerticalOrientation.DOWN;
				standingOn = null;
				horizontalAcceleration = 0;
			}
		}

		if (collision != null) {
			newX = collision.getX();
			newY = collision.getY() - (RADIUS_VERTICAL - 0.5);
//			setPosition(collision.subtract(new Position(0, RADIUS_VERTICAL - 1)));
			newPos = new Position(newX, newY);
			verticalOrientation = VerticalOrientation.NONE;
			verticalSpeed = 0;
			standingOn.interact(this);
			return true;
		}

		newPos = new Position(newX, newY);
		return false;
	}

	private boolean checkCollisionRobot() {
		if (state != State.DEATH) {
			for (Robot toCheck: robots) {
				if (toCheck.state != State.DEATH && toCheck != this) {
					if (this.isOnTopOf(toCheck)) {
						this.kill(toCheck);
						return true;
					}
					
					Position collision = this.collideWithRobot(toCheck);
					if (collision != null) {
						positionRobot(collision, toCheck);
						this.updateLines();
						toCheck.updateLines();
					}
				}				
			}
		}

		return false;
	}
	
	private boolean isOnTopOf(Robot robot) {
		if (this.getVerticalOrientation() == VerticalOrientation.DOWN ||
				robot.getVerticalOrientation() == VerticalOrientation.UP ) {
			for (Line robotLine: robot.headShoulderLines) {
				for (Line line: feetLines)
					if (line.intersection(robotLine) != null)
						return true;
			}
		}

		return false;
	}
	
	/**
	 * 
	 * @param robot
	 * @return The position of the collision with the given robot.
	 * 		   Null if there is no collision.
	 */
	private Position collideWithRobot(Robot robot) // check horizontal collision
	{
//		if (this.horizontalOrientation == HorizontalOrientation.NONE && horizontalSpeed == 0)
//			return null;
		
		Line toCheck;
		if (this.horizontalOrientation == HorizontalOrientation.LEFT)
			toCheck = borderLines[0];
		else // Hij gaat naar rechts
			toCheck = borderLines[1];
		
		Position intersection;
		for (Line other: robot.horizontalLines) {
			intersection = toCheck.intersection(other);
			if (intersection != null)
				return intersection;
		}
		
		return null;
	}
	
	private void positionRobot(Position collision, Robot other) {
		double newX;
		double newXOther = other.newPos.getX();
		if (other.horizontalOrientation == HorizontalOrientation.NONE ||
				other.horizontalOrientation == this.horizontalOrientation) {
			if (this.horizontalOrientation == HorizontalOrientation.LEFT)
				newX = other.getPosition().getX() + 2*RADIUS_HORIZONTAL;
			else
				newX = other.getPosition().getX() - 2*RADIUS_HORIZONTAL;
		} else {
			double middle = (other.getPosition().getX() + this.getPosition().getX()) / 2;
			if (this.horizontalOrientation == HorizontalOrientation.LEFT) { // we are going left
				newX = middle + RADIUS_HORIZONTAL;
				newXOther = middle - RADIUS_HORIZONTAL;
			} else {														// we are going right
				newX = middle - RADIUS_HORIZONTAL;
				newXOther = middle + RADIUS_HORIZONTAL;
			}
		}
		
		this.newPos = new Position(newX, newPos.getY());
		other.newPos = new Position(newXOther, other.newPos.getY());
	}

	//	Deel interactie		//
	
	protected void kill(Robot toKill) {
		if (toKill.state == State.ALIVE) {
			toKill.kill();
			Sound.getInstance(context).killSound();
		}

		jumpWhenKill();
	}

	private void respawn() {
		Random random = new Random();
		float dec = random.nextFloat();
		double pos = random.nextDouble();
		List<GameObject> objects = map.getObjects();
		if (dec < objects.size() / (objects.size() + 2)) //Spawn on the ground
			setPosition(new Position(pos * (MAX_X - RADIUS_HORIZONTAL) + RADIUS_HORIZONTAL,
					MAX_Y - RADIUS_VERTICAL));
		else {
			GameObject respawn = objects.get((int)(dec * objects.size()));
			double x = pos * (respawn.getRect().width()/2 - RADIUS_HORIZONTAL) + RADIUS_HORIZONTAL;
			double y = respawn.getRect().centerY() - respawn.getRect().height()/2 - RADIUS_VERTICAL;
			if (dec < .5)
				setPosition(new Position(respawn.getRect().centerX() + x, y));
			else
				setPosition(new Position(respawn.getRect().centerX() - x, y));

			standingOn = respawn;
		}
		newPos = getPosition();
		state = State.RESPAWNED;
		timeRespawned = RESPAWNED_TIME;
	}


	//	Deel visualisate		//
	
	public Rect getRect() { // TODO nie meer nodig
		double x = getPosition().getX();
		double y = getPosition().getY();

		if (y + RADIUS_VERTICAL <= MIN_Y)
			return new Rect((int)(x - RADIUS_HORIZONTAL), (int)MIN_Y, (int)(x + RADIUS_HORIZONTAL), (int)(MIN_Y + 2 * RADIUS_HORIZONTAL / 3));

		return new Rect((int)(x - RADIUS_HORIZONTAL), (int)(y - RADIUS_VERTICAL),
				(int)(x + RADIUS_HORIZONTAL),(int) (y + RADIUS_VERTICAL));
	}
	
	@Override
	public void draw(Canvas canvas)
	{
		setDrawing();
		if (getPosition().getY() + RADIUS_VERTICAL <= MIN_Y)
			canvas.drawBitmap(ARROW, null, getRect(), null);
		
		if(exploding && currentFrame < 3)
		{
			canvas.drawBitmap(Spritesheet, src1, dst, null);	
			if (Spritesheet_color.getSpriteSheet() != null)
				canvas.drawBitmap(Spritesheet_color.getSpriteSheet(), src1, dst, null);
		}

		canvas.drawBitmap(Spritesheet, src, dst, null);
		if (Spritesheet_color.getSpriteSheet() != null && !exploding)
			canvas.drawBitmap(Spritesheet_color.getSpriteSheet(), src, dst, null);
		
		
		
	}
	
	private void setDrawing()
	{
		// 0 = wait
		// 1 = right
		// 2 = left
		// 3 = die
		// 4 = air up left
		// 5 = air up right
		// 6 = air up center
		// 7 = air down left
		// 8 = air down right
		// 9 = air down center
		
		if(horizontalOrientation == HorizontalOrientation.NONE && verticalOrientation == VerticalOrientation.NONE)
		{
			toDraw = 0;
		}
		if( horizontalOrientation == HorizontalOrientation.LEFT && verticalOrientation == VerticalOrientation.NONE)
		{
			toDraw = 1;
		}
		if( horizontalOrientation == HorizontalOrientation.RIGHT && verticalOrientation == VerticalOrientation.NONE)
		{
			toDraw = 2;
		}
		if(horizontalOrientation == HorizontalOrientation.LEFT && verticalOrientation == VerticalOrientation.UP)
		{
			toDraw = 3;
		}
		if(horizontalOrientation == HorizontalOrientation.RIGHT && verticalOrientation == VerticalOrientation.UP)
		{
			toDraw = 4;
		}
		if(horizontalOrientation == HorizontalOrientation.NONE && verticalOrientation == VerticalOrientation.UP)
		{
			toDraw = 5;
		}
		if(horizontalOrientation == HorizontalOrientation.LEFT && verticalOrientation == VerticalOrientation.DOWN)
		{
			toDraw = 6;
		}
		if(horizontalOrientation == HorizontalOrientation.RIGHT && verticalOrientation == VerticalOrientation.DOWN)
		{
			toDraw = 7;
		}
		if(horizontalOrientation == HorizontalOrientation.NONE && verticalOrientation == VerticalOrientation.DOWN)
		{
			toDraw = 8;
		}
		if(exploding)
		{
			toDraw = 9;
		}
		

		double x = getPosition().getX() - RADIUS_HORIZONTAL;
		double y = getPosition().getY() - RADIUS_VERTICAL;

		if(framesPast >= 10)
		{
			if(currentFrame == 6)
				exploding = false;
			currentFrame = ++currentFrame % 8;
			framesPast = 0;
			
		} else {
			framesPast +=1;
		}
		
		if (state == State.RESPAWNED && framesPast < 3) {
			src = new Rect(0, 0, 0, 0);
		} else {
			int height = Spritesheet.getHeight() / 10 ;
			int width = Spritesheet.getWidth() / 9;
			
			int srcX = currentFrame * width;
			int srcY = toDraw * height;
	
			src = new Rect((srcX), (srcY), srcX + width,srcY + height);
		}

		dst = new Rect((int)(x), (int)(y),
				(int)(x + 2 * RADIUS_HORIZONTAL),(int) (y + 2 * RADIUS_VERTICAL));
	
	}
	
}
